package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.UpShop;
import cn.stylefeng.guns.modular.system.mapper.UpShopMapper;
import cn.stylefeng.guns.modular.system.model.params.UpShopParam;
import cn.stylefeng.guns.modular.system.model.result.UpShopResult;
import  cn.stylefeng.guns.modular.system.service.UpShopService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 开店申请表 服务实现类
 * </p>
 *
 * @author 小飞
 * @since 2019-07-11
 */
@Service
public class UpShopServiceImpl extends ServiceImpl<UpShopMapper, UpShop> implements UpShopService {


    @Autowired
    private UpShopMapper upShopMapper;


    @Override
    public void add(UpShopParam param){
        UpShop entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(UpShopParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(UpShopParam param){
        UpShop oldEntity = getOldEntity(param);
        UpShop newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public UpShopResult findBySpec(UpShopParam param){
        return null;
    }

    @Override
    public List<UpShopResult> findListBySpec(UpShopParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(UpShopParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(UpShopParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private UpShop getOldEntity(UpShopParam param) {
        return this.getById(getKey(param));
    }

    private UpShop getEntity(UpShopParam param) {
        UpShop entity = new UpShop();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


     /**
     * 新增申请人id
     */
     @Override
     public int insertStoreId(){
         return upShopMapper.insertStoreId();
     }


    /**
     * 修改操作，设置申请人
     */
    public Integer UpdateUpShop(UpShopParam param){
        return upShopMapper.UpdateUpShop(param);
    }


    /**
     * 根据删除数据
     */
    public int DeleteStoreId(@Param("storeId") Long storeId){
        return upShopMapper.DeleteStoreId(storeId);
    }

    @Override
    public UpShop getByProcessInstanceId(String processInstanceId) {
        return this.baseMapper.getByProcessInstanceId(processInstanceId);
    }


}
